package main

import (
	"fmt"
	"time"
)


func main(){
	
	//获取当前时间
	now := time.Now()
	fmt.Printf("now=%v,type=%T\n",now,now)

	//通过nwo获取年月日时分秒
	fmt.Printf("year=%v\n",now.Year())
	fmt.Printf("mouth=%v\n",now.Month())
	fmt.Printf("mouth local=%v\n",int(now.Month()))
	fmt.Printf("day=%v\n",now.Day())
	fmt.Printf("hour=%v\n",now.Hour())
	fmt.Printf("Minute=%v\n",now.Minute())
	fmt.Printf("Second=%v\n",now.Second())

	//格式化日期 使用Sprintf
	fmt.Printf("当前年月日 %d-%d-%d %d:%d:%d \n",now.Year(),now.Month(),now.Day(),now.Hour(),now.Minute(),now.Second())
	nowDate := fmt.Sprintf("当前年月日 %d-%d-%d %d:%d:%d \n",now.Year(),now.Month(),now.Day(),now.Hour(),now.Minute(),now.Second())
	fmt.Println("nowDate = ",nowDate)

	//格式化日期  time.Format 2006-01-02 15:04:05 为固定值 等同与 yyyy-MM-dd Hh:mm:ss 数字不能改变  变态
	nowDate = now.Format("2006/01/02 15:04:05")
	fmt.Println("nowDate = ",nowDate)
	nowDate = now.Format("2006/01/02")
	fmt.Println("nowDate = ",nowDate)
	nowDate = now.Format("15:04:05")
	fmt.Println("nowDate = ",nowDate)


	// 时间的常量 获取时间指定单位
	//time.Nanosecond  = 1 //纳秒
	// time.Microsecond

	i:=0
	for{
		i++
		fmt.Println(i)
		//休眠1秒 
		//time.Sleep(time.Second)
		//如果要休眠 0.1 不能使用  time.Second * 0.1 需要使用 time.Millisecond
		time.Sleep(time.Millisecond)
		if i == 100{
			break
		}

	}

	//获取当前时间 秒 纳秒  用来获取随机数字
	//纳秒
	nown := now.UnixNano()
	fmt.Println("nown=",nown)
	//秒
	nowm := now.Unix()
	fmt.Println("nowm=",nowm)







		



}